module.exports = function ($scope, $resource, $modalInstance, toaster) {

	$resource('/api/as/sc/office/getCompanyBaseInfo', {}, {}).save({}, function(res){
		if(res.errcode === 0){
			$scope.param = {
				'company_name': res.data.name,
				'master': res.data.master,
				'phone': res.data.mobile
			}
		} else {
			toaster.error({title: '', body: '查询商户信息失败，请重试'});
		}
	});
	
	$scope.save = function() {
		if($scope.param.phone && !(/^1[3|4|5|7|8|9]\d{9}$/.test($scope.param.phone))){
            toaster.warning({title: '', body: '手机号格式不正确'});
            return;
		}
		$resource('/api/as/sc/office/updateMaster', {}, {}).save($scope.param, function(res){
			if(res.errcode === 0){
				toaster.success({title: '', body: '修改成功'});
				$modalInstance.close();
			} else {
				toaster.error({title: '', body: '修改失败'});
			}
		});
	}

	$scope.cancel = function() {
        $modalInstance.dismiss('cancel'); 
	};

};